// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Gem Block Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 12 : TYPE_GEMBLOCK

// Function declarations
reserve function GemBlock_DebugDraw
reserve function GemBlock_DebugSpawn

// Static Values
public value GemBlock_value15 = 0;

// Tables

function GemBlock_DebugDraw
	temp4 = object[0].value10
	temp4 -= GemBlock_value15
	DrawSprite(temp4)
end function


function GemBlock_DebugSpawn
	temp4 = object[0].value10
	temp4 -= GemBlock_value15
	temp5 = 12
	CallFunction(DebugMode_SpawnObject)
	object[arrayPos0].drawOrder = 4
	object[arrayPos0].groupID = GROUP_BLOCKS
end function


event ObjectMain
	if object.state == 1
		object.propertyValue = object.value0
		object.propertyValue >>= 1
		object.propertyValue &= 3
		object.value0++
		if object.value0 == 16
			object.priority = PRIORITY_ACTIVE_BOUNDS
			object.value0 = 0
			object.propertyValue = object.value1
			object.propertyValue++
			if object.propertyValue == 4
				object.type = TypeName[Blank Object]
			else
				object.state = 0
			end if
			SpecialSetup_value11 = 0
		end if
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			CallFunction(SpecialSetup_Function10)
		next
	else
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			CallFunction(SpecialSetup_Function10)
			if SpecialSetup_value11 == 0
				if checkResult > 0
					object.state = 1
					object.priority = PRIORITY_ACTIVE
					SpecialSetup_value11 = 1
					object.value1 = object.propertyValue
					if PlayerObject_value4 == 0
						PlaySfx(SfxName[Gem Block], 0)
					end if
				end if
			end if
		next
	end if
end event


event ObjectDraw
	CallFunction(SpecialSetup_Function9)
	temp2 = SpecialSetup_value10
	temp2 /= 5
	switch temp2
	case 0
		object.direction = FLIP_NONE
		break
	case 1
		object.direction = FLIP_X
		break
	case 2
		object.direction = FLIP_XY
		break
	case 3
		object.direction = FLIP_Y
		break
	end switch
	DrawSpriteFX(object.propertyValue, FX_FLIP, temp0, temp1)
end event


event ObjectStartup
	LoadSpriteSheet("Special/Objects.gif")
	SpriteFrame(-12, -12, 24, 24, 301, 76)
	SpriteFrame(-12, -12, 24, 24, 326, 76)
	SpriteFrame(-12, -12, 24, 24, 351, 76)
	SpriteFrame(-12, -12, 24, 24, 376, 76)
	foreach (TypeName[Gem Block], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].groupID = GROUP_BLOCKS
	next
	temp0 = 0
	GemBlock_value15 = DebugMode_ObjCount
	while temp0 < 4
		SetTableValue(TypeName[Gem Block], DebugMode_ObjCount, DebugMode_TypeTable)
		SetTableValue(GemBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
		SetTableValue(GemBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
		DebugMode_ObjCount++
		temp0++
	loop
end event

event RSDKDraw
	DrawSprite(object.propertyValue)
end event

event RSDKLoad
	LoadSpriteSheet("Special/Objects.gif")
	SpriteFrame(-12, -12, 24, 24, 301, 76)
	SpriteFrame(-12, -12, 24, 24, 326, 76)
	SpriteFrame(-12, -12, 24, 24, 351, 76)
	SpriteFrame(-12, -12, 24, 24, 376, 76)
end event
